package per.ethan.springboot.basic.service;

import com.baomidou.mybatisplus.extension.service.IService;
import per.ethan.springboot.basic.entity.BaseEntity;
import per.ethan.springboot.basic.entity.Page;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * @author Ethan
 * @date 2020/06/18 14:49
 */
public interface BaseService<Entity extends BaseEntity> extends IService<Entity> {

    Long create(Entity entity);

    List<Long> batchSave(List<Entity> entityList);

    boolean logicRemoveById(Long id);

    boolean logicRemoveByIds(List<Long> idList);

    boolean removeByWhere(Entity entity);

    boolean logicRemoveByWhere(Entity entity);

    List<Entity> listByWhere(Entity entity);

    Page<Entity> listByPage(Page<Entity> page);

    default Class<Entity> getTarget() {

        Class clazz = this.getClass();
        //获取父类
        Type type = clazz.getGenericSuperclass();
        //获取泛型
        ParameterizedType params = (ParameterizedType) type;
        //获取泛型的类型
        Type[] actualTypeArguments = params.getActualTypeArguments();
        return (Class<Entity>) actualTypeArguments[1];

    }

}
